package fox.framework.rpc.context;

import fox.framework.rpc.client.RpcRegister;
import fox.framework.rpc.client.invocation.ConsumeInvoker;
import fox.framework.rpc.client.message.FoxRequestInterceptor;
import fox.framework.rpc.client.message.RpcClientRequestInterceptor;
import fox.framework.rpc.client.node.rule.RoundRobinRuleFactory;
import fox.framework.rpc.client.node.rule.RuleFactory;
import fox.framework.rpc.context.event.RpcEventListener;
import fox.framework.rpc.context.processor.RpcApplicationProcessor;
import fox.framework.rpc.converter.CommonExceptionConverter;
import fox.framework.rpc.converter.KryoConverter;
import fox.framework.rpc.converter.RpcMessageConverter;
import fox.framework.rpc.server.dispatcher.invoke.ProvideInvoker;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author cuichao
 * @Description: DefaultRpcApplicationConfigurer
 * @Date: create in 2021/2/2 20:15
 */
class DefaultRpcApplicationConfigurer implements RpcApplicationConfigurer {

    private String name;

    private int port;

    private String bind;

    private String protocol = "fox";

    private String globalConverterName = "kryo";

    private String group = "default";

    private RpcRegister register;

    private RuleFactory ruleFactory = new RoundRobinRuleFactory();

    private List<RpcMessageConverter> converters = new ArrayList<>();

    private List<RpcClientRequestInterceptor> interceptors = new ArrayList<>();

    private List<ProvideInvoker> provideInvokers = new ArrayList<>();

    private List<ConsumeInvoker> consumeInvokers = new ArrayList<>();

    private List<RpcApplicationProcessor> processors = new ArrayList<>();

    private Set<RpcEventListener> listeners = new HashSet<>();

    public DefaultRpcApplicationConfigurer() {
        init();
    }

    private void init(){
        converters.add(new KryoConverter());
        converters.add(new CommonExceptionConverter());
        interceptors.add(new FoxRequestInterceptor());
    }


    @Override
    public String getApplicationName() {
        return name;
    }

    @Override
    public int getPort() {
        return port;
    }

    @Override
    public String getBind() {
        return bind;
    }

    @Override
    public String getGlobalProtocol() {
        return protocol;
    }

    @Override
    public String getGlobalConverterName() {
        return globalConverterName;
    }

    @Override
    public String getGlobalGroup() {
        return group;
    }

    @Override
    public RpcRegister getRegister() {
        return register;
    }

    @Override
    public RuleFactory getGlobalRuleFactory() {
        return ruleFactory;
    }

    @Override
    public List<RpcMessageConverter> getRpcMessageConverter() {
        return converters;
    }

    @Override
    public List<RpcClientRequestInterceptor> getClientRequestInterceptors() {
        return interceptors;
    }

    @Override
    public List<ProvideInvoker> getProvideInvokers() {
        return provideInvokers;
    }

    @Override
    public List<ConsumeInvoker> getConsumeInvokers() {
        return consumeInvokers;
    }

    @Override
    public List<RpcApplicationProcessor> getApplicationProcessors() {
        return processors;
    }

    @Override
    public Set<RpcEventListener> getRpcEventListeners() {
        return listeners;
    }

}
